﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SpaceNeedle.x6473.WindowsPhone.ViewModels;
using SpaceNeedle.x6473.WindowsPhone.Common;
using Windows.Networking.Connectivity;
using SpaceNeedle.SDK.WindowsPhone.Views;
using SpaceNeedle.x6473.WindowsPhone.Models;
using Microsoft.Phone.Tasks;
using SpaceNeedle.SDK.WindowsPhone;

namespace SpaceNeedle.x6473.WindowsPhone.Views
{
    public class TicketsView : ViewBase<TicketsViewModel> { }
    public partial class Tickets : TicketsView
    {
        public Tickets()
        {
            InitializeComponent();
        }

        private void OnTicketsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
            {
                return;
            }

            AppViewModel.Instance.Properties.SelectedRequestItem = e.AddedItems[0] as Models.RequestItem;
            AppServices.Current.NavigationService.NavigateDirect(ViewsUris.RequestItemDetails);
        }

        private void OnUploadsMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.UploadsCommand.Execute(null);
        }

        private void OnAboutMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.AboutCommand.Execute(null);
        }

        private void OnSignOutMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.SignOutCommand.Execute(null);
        }

        private void OnShareTicket_Click(object sender, RoutedEventArgs e)
        {
            RequestItem item = (sender as MenuItem).Tag as RequestItem;

            ShareLinkTask shareLinkTask = new ShareLinkTask();
            shareLinkTask.LinkUri = new Uri(item.Permalink, UriKind.Absolute);
            shareLinkTask.Message = item.Description;

            shareLinkTask.Show();
        }
    }
}